const root = '/proxy';

function sleep(timestamp: number) {
    return new Promise(function (resolve) {
        return setTimeout(function () {
            return resolve(timestamp);
        }, timestamp);
    });
}

export default {
    // 模拟通用帮助接口
    [`GET ${root}/SUP/RichHelp/GetHelpTabFlg`]: (_: any, res: any) => res.send('listStyle'),
    [`GET ${root}/SUP/RichHelp/GetHelpInfo`]: function (_: any, res: any) {
        res.send({
            status: 'ok',
            data: {
                Title: '城市帮助',
                columns: [
                    { dataIndex: 'value', header: '城市编号', flex: 1 },
                    { dataIndex: 'label', header: '城市名称', flex: 1 }
                ],
                showTree: '0',
                showList: '1',
                helpLang: '{}',
                isShowSearch: true,
                querySearchList: [{
                    ORMMode: true,
                    listFields: 'No,Name,PhId',
                    listHeadTexts: '代码,名称',
                    showAutoHeader: false,
                    usercodeField: 'value',
                    valueField: 'value',
                    displayField: 'label',
                    helpid: 'holidaytype',
                    matchFieldWidth: false,
                    clientSqlFilter: '',
                    id: null,
                    xtype: 'ngRichHelp',
                    fieldLabel: '请假类型',
                    name: 'Ctype*int32*eq*1',
                    mustInput: false,
                    colspan: 1,
                    iconCls: null,
                    value: '',
                    itemId: 'Ctype',
                    FieldUIId: null,
                    langKey: null
                },
                {
                    ORMMode: true,
                    listFields: 'Phid,Cname,Phid',
                    listHeadTexts: '代码,名称',
                    showAutoHeader: false,
                    usercodeField: 'value',
                    valueField: 'value',
                    displayField: 'label',
                    helpid: 'holidayname',
                    matchFieldWidth: false,
                    clientSqlFilter: 'type=1',
                    id: null,
                    xtype: 'ngRichHelp',
                    fieldLabel: '假种1',
                    name: 'PhidHolitype*int64*eq*1',
                    mustInput: false,
                    colspan: 1,
                    iconCls: null,
                    value: '',
                    itemId: 'PhidHolitype',
                    FieldUIId: null,
                    langKey: null
                },
                {
                    data: [
                        { code: '1', name: '新增' },
                        { code: '2', name: '请假审批中' },
                        {
                            code: '3',
                            name: '请假已审批'
                        },
                        { code: '4', name: '销假' },
                        { code: '5', name: '销假审批中' },
                        { code: '6', name: '已销假' },
                        {
                            code: '7',
                            name: '作废'
                        },
                        { code: '8', name: '作废审批中' }
                    ],
                    queryMode: 'local',
                    editable: true,
                    ORMMode: true,
                    listFields: null,
                    listHeadTexts: null,
                    showAutoHeader: false,
                    valueField: null,
                    displayField: null,
                    helpid: '',
                    matchFieldWidth: true,
                    usercodeField: null,
                    clientSqlFilter: '',
                    id: null,
                    xtype: 'ngComboBox',
                    fieldLabel: '状态',
                    name: 'Cstatus*int32*eq*1',
                    mustInput: false,
                    colspan: 1,
                    iconCls: null,
                    value: '',
                    itemId: 'Cstatus',
                    FieldUIId: null,
                    langKey: null
                },
                {
                    id: null,
                    xtype: 'ngDateTime',
                    fieldLabel: '请假开始时间',
                    name: 'Factbdt*date*ge*1',
                    mustInput: false,
                    colspan: 1,
                    iconCls: null,
                    value: '',
                    itemId: 'Factbdt',
                    FieldUIId: null,
                    langKey: 'Factbdt*date*ge*1'
                },
                {
                    id: null,
                    xtype: 'ngDateTime',
                    fieldLabel: '至',
                    name: 'Factbdt*date*le*1',
                    mustInput: false,
                    colspan: 1,
                    iconCls: null,
                    value: '',
                    itemId: 'Factbdt',
                    FieldUIId: null,
                    langKey: 'Factbdt*date*le*1'
                },
                {
                    decimalPrecision: 2,
                    decimalSeparator: '.',
                    isInQuerySetting: true,
                    showPercent: false,
                    step: 1.0,
                    id: null,
                    xtype: 'ngNumber',
                    fieldLabel: '请假天数',
                    name: 'Factday*number*eq*1',
                    mustInput: false,
                    colspan: 1,
                    iconCls: null,
                    value: null,
                    itemId: 'Factday',
                    FieldUIId: null,
                    langKey: null
                },
                {
                    maxLength: 200,
                    id: null,
                    xtype: 'ngText',
                    fieldLabel: '请假事由',
                    name: 'Reason*str*like*1',
                    mustInput: false,
                    colspan: 3,
                    iconCls: null,
                    value: '',
                    itemId: 'Reason',
                    FieldUIId: null,
                    langKey: 'Reason*str*like*1'
                }]
            }
        });
    },
    [`GET ${root}/SUP/RichHelp/SetHelpTabFlg`]: (_: any, res: any) => res.send(''),
    [`POST ${root}/SUP/RichHelp/GetHelpList`]: function (_: any, res: any) {
        const record = [
            { value: '10000', label: '北京' },
            { value: '10001', label: '北京1111111111111111111111111111' },
            { value: '10002', label: '杭州' },
            { value: '10003', label: '武汉' },
            { value: '10004', label: '上海' },
            { value: '10005', label: '广州' }
        ];
        res.send({
            totalRows: record.length,
            Record: record
        });
    },
    [`GET ${root}/SUP/RichHelp/SaveCommonUseData`]: {
        Status: 'success'
    },
    [`GET ${root}/SUP/RichHelp/DeleteCommonUseData`]: {
        Status: 'success'
    },
    [`GET ${root}/SUP/RichHelp/GetCommonUseList`]: function (_: any, res: any) {
        const record = [
            { value: '10000', label: '北京' },
            { value: '10005', label: '广州' }
        ];
        res.send({
            totalRows: record.length,
            Record: record
        });
    },
    [`POST ${root}/SUP/RichHelp/saveLastUseData`]: {
        Status: 'success'
    },
    [`GET ${root}/SUP/RichHelp/getLastUseList`]: function (_: any, res: any) {
        const record = [
            { value: '10000', label: '北京' },
            { value: '10005', label: '广州' }
        ];
        res.send({
            totalRows: record.length,
            Record: record
        });
    },
    // 内嵌查询
    [`POST ${root}/SUP/QueryPanel/SetQueryPanelData`]:{},
    [`GET ${root}/SUP/QueryPanel/GetIndividualQueryPanel`]: {
        list: [
            {
                maxLength: 200,
                id: null,
                xtype: 'ngText',
                fieldLabel: '单据编码好长好长好长',
                name: 'Cno*str*like*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'Cno',
                FieldUIId: null,
                langKey: 'Cno*str*like*1'
            },
            {
                maxLength: 200,
                id: null,
                xtype: 'ngText',
                fieldLabel: '请假主题内容',
                name: 'Cname*str*like*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'Cname',
                FieldUIId: null,
                langKey: 'Cname*str*like*1'
            },
            {
                maxLength: 100,
                id: null,
                fieldLabel: '请假人',
                name: 'PhidEmp*int64*eq*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'PhidEmp',
                FieldUIId: null,
                langKey: 'PhidEmp*int64*eq*1'
            },
            {
                ORMMode: true,
                listFields: 'No,Name,PhId',
                listHeadTexts: '代码,名称',
                showAutoHeader: false,
                usercodeField: 'value',
                valueField: 'value',
                displayField: 'label',
                helpid: 'holidaytype',
                matchFieldWidth: false,
                clientSqlFilter: '',
                id: null,
                xtype: 'ngRichHelp',
                fieldLabel: '请假类型',
                name: 'Ctype*int32*eq*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'Ctype',
                FieldUIId: null,
                langKey: null
            },
            {
                ORMMode: true,
                listFields: 'Phid,Cname,Phid',
                listHeadTexts: '代码,名称',
                showAutoHeader: false,
                usercodeField: 'value',
                valueField: 'value',
                displayField: 'label',
                helpid: 'holidayname',
                matchFieldWidth: false,
                clientSqlFilter: 'type=1',
                id: null,
                xtype: 'ngRichHelp',
                fieldLabel: '假种1',
                name: 'PhidHolitype*int64*eq*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'PhidHolitype',
                FieldUIId: null,
                langKey: null
            },
            {
                data: [
                    { code: '1', name: '新增' },
                    { code: '2', name: '请假审批中' },
                    {
                        code: '3',
                        name: '请假已审批'
                    },
                    { code: '4', name: '销假' },
                    { code: '5', name: '销假审批中' },
                    { code: '6', name: '已销假' },
                    {
                        code: '7',
                        name: '作废'
                    },
                    { code: '8', name: '作废审批中' }
                ],
                queryMode: 'local',
                editable: true,
                ORMMode: true,
                listFields: null,
                listHeadTexts: null,
                showAutoHeader: false,
                valueField: null,
                displayField: null,
                helpid: '',
                matchFieldWidth: true,
                usercodeField: null,
                clientSqlFilter: '',
                id: null,
                xtype: 'ngComboBox',
                fieldLabel: '状态',
                name: 'Cstatus*int32*eq*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'Cstatus',
                FieldUIId: null,
                langKey: null
            },
            {
                id: null,
                xtype: 'ngDateTime',
                fieldLabel: '请假开始时间',
                name: 'Factbdt*date*ge*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'Factbdt',
                FieldUIId: null,
                langKey: 'Factbdt*date*ge*1'
            },
            {
                id: null,
                xtype: 'ngDate',
                fieldLabel: '至',
                name: 'Factbdt*date*le*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: '',
                itemId: 'Factbdt',
                FieldUIId: null,
                langKey: 'Factbdt*date*le*1'
            },
            {
                decimalPrecision: 2,
                decimalSeparator: '.',
                isInQuerySetting: true,
                showPercent: false,
                step: 1.0,
                id: null,
                xtype: 'ngNumber',
                fieldLabel: '请假天数',
                name: 'Factday*number*eq*1',
                mustInput: false,
                colspan: 1,
                iconCls: null,
                value: null,
                itemId: 'Factday',
                FieldUIId: null,
                langKey: null
            },
            {
                maxLength: 200,
                id: null,
                xtype: 'ngText',
                fieldLabel: '请假事由',
                name: 'Reason*str*like*1',
                mustInput: false,
                colspan: 3,
                iconCls: null,
                value: '',
                itemId: 'Reason',
                FieldUIId: null,
                langKey: 'Reason*str*like*1'
            }
        ],
        rememberstr: '{}',
        langInfo: '{}',
        sortfilter: '',
        ischeck: '1'
    },
    [`GET ${root}/SUP/QueryPanel/GetIndividualQueryPanelInfo`]: { Record: [] },
    [`GET ${root}/MDP/BusObj/QuerySetting/GetSchemeListByPageId`]: {
        totalRows: 2,
        items: [
            {
                phid: 579220914000001,
                cname: '方案一',
                bustype: 6162,
                status: '1',
                belong: 579191010000003
            },
            {
                phid: 579220914001001,
                cname: '方案二',
                bustype: 6162,
                status: '1',
                belong: 579191010000003
            }
        ]
    },
    [`${root}/SUP/IndividualUI/GetIndividualUIContent`]: function (_: any, res: any) {
        const json = require(`./${queryURLParams(_.url).busType}.json`);
        res.send({
            Status: 'success',
            Data: json
        });
    },
    [`GET ${root}/PCM/TCNT/TCntM/getTCntMList`]: {code: 0, total: 0, list: []},
    [`GET ${root}/PCM/TCNT/TCntM/getAllData`]:  {code: 0, data: {}},
};

function queryURLParams(url: string) {
    let pattern = /(\w+)=(\w+)/ig; //定义正则表达式
    let parames: any = {}; // 定义参数对象
    url.replace(pattern, (_, $1, $2) => {
        parames[$1] = $2;
        return "";
    });
    return parames;
}